//响应提示工具类型
import {ElMessage} from "element-plus";

export const response = function () {
	
	function handle({data,success,error,successFn,failFn,log}) {
		if(log){
			console.log(`${log}：`,data)
		}
		if(data.code === 200){
			if (success){
				ElMessage.success(success)
			}
			if(successFn) {
				successFn();
			}
		}else if(data.code === 405){
			ElMessage.error('操作失败，您的权限不足！');
		}else if(data.code === 401){
			ElMessage.error('用户未登录，请先登录！')
		}else if(data.code === 402){
			ElMessage.error('用户登录过期')
		} else{
			if(error){
				ElMessage.error(error)
			}
			if(failFn!=null){
				failFn();
			}
		}
	}
	
	function loadPageInfo({data,executeFn,hint,log}){
		if(log){
			console.log(log,data)
		}
		if(data){
			if(hint){
				ElMessage.success('刷新成功')
			}
		}
		if(executeFn){
			executeFn();
		}
	}
	
	return{
		handle,
		loadPageInfo
	}
}();